package com.my.mymafengwo.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * ***********************************************
 * author:wgh
 * time:2015/12/1 17:01
 * copyright:
 * name:
 * step:
 * ***********************************************
 */
public class SharedPrefUtils {

    private static SharedPreferences mSharePref;
    private static final String SHAREDPREF_NAME = "config";
    /**
     * 是否是第一次开启软件
     */
    public static final String ISFIRST = "isFirst";
    /**
     * 是否已经登录
     */
    public static final String ISLOGIN = "isLogin";

    /**
     * 得到boolean值
     *
     * @param context
     * @param key
     * @param defValue 默认的返回值
     * @return
     */
    public static Boolean getBoolean(Context context, String key, Boolean defValue) {
        if (mSharePref == null) {
            mSharePref = context.getSharedPreferences(SHAREDPREF_NAME, Context.MODE_PRIVATE);
        }
        return mSharePref.getBoolean(key, defValue);
    }

    /**
     * 保存boolean值
     *
     * @param context
     * @param key
     * @param value
     */
    public static void saveBoolean(Context context, String key, Boolean value) {
        if (mSharePref == null) {
            mSharePref = context.getSharedPreferences(SHAREDPREF_NAME, Context.MODE_PRIVATE);
        }
        mSharePref.edit().putBoolean(key, value).commit();
    }
}
